
document.domain = "dwusoftdev.com";
var picStoreAction = "http://pic.dwusoftdev.com/pic/upload-media.action?isRemote=T";

function Supload(myPos,idname,fileType,imgW,imgH,sImgH,sImgW,callback){
	 if($("#sampleUW")){
		$("#sampleUW").replaceWith("");
	}
	 var mydom = "<div id=\"sampleUW\" class=\"easyui-window\" "+
			 " iconCls=\"icon-ok\">" +
			 "<div class=\"easyui-layout\" fit=\"true\">"+
			 "<form target=\"uploadIframe\" name=\"uploadMedia\" id=\"uploadMedia\" action=\""+picStoreAction+"\" method=\"POST\" enctype=\"multipart/form-data\">"+
			 "<input type=\"hidden\"  name=\"callback\" value="+callback + "/>"+
			 "<span id=\"upLable\"></span>：<input type=\"file\" name=\"upload\" id=\"uploadP\"/>"+
			 "<input type=\"hidden\" id=\"fileType\" name=\"fileType\" value=\""+fileType+"\"/>"+
			 "<input type=\"hidden\" id=\"idname\" name=\"idname\" value=\""+idname+"\"/>"+
			 "<input type=\"button\" onclick=\"uploadFile('"+fileType+"');\" style=\"width:80px;\"  value=\"上传\"/>"+
			 "<input type=\"button\" onclick=\"clo();\" style=\"width:80px;\"  value=\"关闭\"/>"+
			 "<input type=\"button\" id=\"picuplBut\" onclick=\"togWHtext();\" style=\"width:100px;\"  value=\"修改图片大小\"/>"+
			 "<div id=\"whdivupl\">" +
			 "标准图高度:<input type=\"text\" id=\"imgH\" name=\"imgH\" value=\""+imgH+"\"/><br>"+
			 "标准图宽度:<input type=\"text\" id=\"imgW\" name=\"imgW\" value=\""+imgW+"\"/><br><br><br>" ;
			if((sImgH != '' && sImgH  != undefined ) ||  (sImgW != '' && sImgW != undefined)){
				mydom+= "缩略图高度:<input type=\"text\" id=\"sImgH\" name=\"sImgH\" value=\""+sImgH+"\"/><br>"+
				  "缩略图宽度:<input type=\"text\" id=\"sImgW\" name=\"sImgW\" value=\""+sImgW+"\"/><br>" ;
			}
			mydom+=  "</div>"+
			 "</form><div id=\"upmeDiv\" style=\"left: 125px;top: 60px;\"><span id=\"uphistory\"></span></div>"+
			 		"<iframe name=\"uploadIframe\" frameborder=0  height=0 width=0></iframe></div>";
	 if($("#sampleUW").attr("class")!=undefined){
	 	if($("#uploadP").val() != ""){
		 	$("#uphistory").html("<font color=\"red\">你之前上传的文件是：</font>"+$("#uploadP").val());
		 	$("#uploadP").val("");
	 	}
	 	$("#imgH").val(imgH);
	 	$("#imgW").val(imgW);
	 	$("#fileType").val(fileType);
	 	$("#idname").val(idname);
		resizeWin('sampleUW','媒体资料上传');
	 }else{
		 $("body").append(mydom);
		 resizeWin('sampleUW','媒体资料上传');
	 }
	 dilogic(fileType);
}
function resizeWin(sw,tit){
	$('#'+sw).window({
					title: tit,
					width: 530,
					modal: false,
					shadow: false,
					closed: false,
					height: 175
		 });
}

function dilogic(fileType){
	 if(fileType == "pic"){
	 	 $("#whdivupl").hide();
		 $('#picuplBut').show();
	 	 $("#upLable").html("图片");
	 }else if(fileType == "video"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 	
	 	 $("#upLable").html("视频文件");
	 	 $("#previewImg").remove();
	 }else if(fileType=="flash"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 	
	 	 $("#upLable").html("flash文件");
	 	 $("#previewImg").remove();
	 }else{//if(fileType=="file"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 
	 	 $("#upLable").html("文件");
	 	 $("#previewImg").remove();
	 }
}
function clo(){
	 $("#sampleUW").window("close");
}
function messgeDis(idname,flag,ft,msg,murl){
	if(flag == "T"){
		 $.messager.alert("上传结果",msg, "info");
		 $("#"+idname).val(murl);
		 if(ft == "pic"){
			 $("#previewImg").attr("src",murl);
		 }
	}else{
		sampleErrorMsg(msg);
	}
}
function togWHtext(){
	$("#whdivupl").toggle();
}
function sampleErrorMsg(msg){
		$.messager.alert("错误提示",msg, "error");
}

function uploadFile(fileType){
	var uploadP = $("#uploadP");
	if(uploadP.val() == null ||  $.trim(uploadP.val()).length == 0){
		sampleErrorMsg("请选择要上传的文件!");
		return;
	}
	document.getElementById("uploadMedia").submit();
}